#!/bin/sh

BUILD_DIR="${BUILD_DIR:-build}"
INSTALL_DIR="${INSTALL_DIR:-install}"

# Build
rm -rf $BUILD_DIR
cmake -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR
cmake --build $BUILD_DIR

# Install
rm -rf $INSTALL_DIR
cmake --install $BUILD_DIR

# Get version
if [ "$#" -ne 1 ]; then
	VER="$(awk -F= '$1~/CMAKE_PROJECT_VERSION:STATIC/{print$2}' $BUILD_DIR/CMakeCache.txt)"
else
	VER=$1
fi

# Zip
cd $INSTALL_DIR
mv latest imrad-$VER
zip -r imrad-$VER-linux64.zip . 

